<?php 
namespace app\forms\taglib;

use think\template\TagLib;
class forms extends Taglib{

    protected $tags = [
        'form'          =>  ['attr'=>'id,name,return','close'=>0],
    ];

    public function tagform($tag,$content) {
        if (!isset($tag['return'])) {//return为空 返回空
            $tag['return'] = '_data';
        }
        $str = '';
        $str .="<?php ";
        $str .="\${$tag['return']} = [];";
        $str .="\$_where = [];";
        // 解析 id/name 限制
        if (isset($tag['id'])) {
            if ('$' == substr($tag['id'],0,1)) {
                $tag['id']   = $this->autoBuildVar($tag['id']);
                $str .="\$_where['id'] = {$tag['id']};";
            }else{
                $str .="\$_where['id'] = '{$tag['id']}';";
            }
        }elseif (isset($tag['name'])) {
            if ('$' == substr($tag['name'],0,1)) {
                $tag['name']   = $this->autoBuildVar($tag['name']);
                $str .="\$_where['name'] = {$tag['name']};";
            }else{
                $str .="\$_where['name'] = '{$tag['name']}';";
            }
        }
        
        $str .="\$_where['status'] = ['eq',1];";
        $str .="\$_m = \\app\\forms\\model\\Forms::where(\$_where);";
        $str .="\${$tag['return']} = \$_m -> find();";
        $str .=" ?>";
        return $str;
    }

}